package logic

import (
	"context"
	"month/api/internal/svc"
	"month/api/internal/types"
	"month/rpc/monthclient"
	"strconv"

	"github.com/zeromicro/go-zero/core/logx"
)

type FileUpLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFileUpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileUpLogic {
	return &FileUpLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FileUpLogic) FileUp(req *types.FileUpRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	name := req.Name
	file := req.File
	vl := req.Vl
	uid := req.Uid

	d, err := l.svcCtx.MonthRpc.FileUp(l.ctx, &monthclient.FileUpRequest{
		Name: name,
		File: file,
		Vl:   vl,
		Uid:  strconv.Itoa(int(uid)),
	})

	return &types.Response{
		Code:    d.Code,
		Message: d.Message,
		Data:    d.Data,
	}, err
}
